package com.dao.dba;

import com.enitiy.Dba;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * 创建作者 ：MySunshine
 * 创建时间 2022/10/24 15:22
 * 项目名称 SHUSHAN
 */
public class DbaDaoImpl implements DbaDao {
    QueryRunner qr = new QueryRunner(new ComboPooledDataSource());
    @Override //管理员登录
    public Dba DbaLogin(int num, String pwd) throws SQLException {
        String sql="select * from dba where dnum=? and pwd=?";
        return  qr.query(sql,new BeanHandler<Dba>(Dba.class),num,pwd);
    }

    @Override    //根据账号查询
    public Dba DbaSelectByNum(int num) throws SQLException {
        String sql="select * from dba where dnum=?";
        return   qr.query(sql,new BeanHandler<Dba>(Dba.class),num);
    }

    @Override
    public boolean DbaUpdateByNum(Dba dba) throws SQLException {
        String sql="update dba set name=? , pwd=? ,rank=? where dnum=? ";
        int update = qr.update(sql, dba.getName(), dba.getPwd(), dba.getRank(), dba.getDnum());
        return update>=1?true:false;
    }
}
